﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace UnitTests
{
	public abstract class TestCaseBase
	{
		private static int nextTestId;
		private List<string> errors = new List<string>();
		public TestCaseBase()
		{
			this.TestCaseID = ++nextTestId;
			this.Name = this.GetType().Name;
		}

		public string Name { get; private set; }

		public int TestCaseID { get; private set; }
		public string[] ErrorMessages
		{
			get
			{
				return this.errors.ToArray();
			}
		}

		public void LogError(string message)
		{
			this.errors.Add(message);
		}

		public bool DoTest()
		{
			try
			{
				this.DoTestImplementation();
			}
			catch (Exception e)
			{
				this.LogError("EXCEPTION THROWN! (" + e.GetType().Name + ") \n" + e.Message + "\n" + e.StackTrace);
			}
			return this.errors.Count == 0;
		}

		protected abstract void DoTestImplementation();
	}
}
